App({
  siteInfo: require("siteinfo.js"),
  onLaunch: function() {
    var e = require("siteinfo.js");
    wx.setStorageSync("siteroot", e.siteroot);
    this.requestLocation();
  },
  requestLocation:function(){
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userLocation']) {
        } else {
          wx.showModal({
            title: '定位权限',
            content: '未授权哦',
            success(res) {
              if (res.confirm) { 
                wx.openSetting({
                  success(res) {
                    console.log(res.authSetting)
                  }
                })
              } else if (res.cancel) { 
              }
            }
          })
        }
      }
    })
  },
  onShow: function() {},
  onHide: function() {},
  onError: function(e) {},
  getUrl: function(t) {
    var e = this.globalData.url;
    if(e!=undefined){
      t.setData({
        url: e
      });
    };
    var a = this;
    e || a.util.request({
      url: "entry/wxapp/Url",
      success: function(e) {
        a.globalData.url = e.data, a.getUrl(t);
      }
    });
  },
  getSystem: function(t) {


    var e = this.globalData.color,a = this.globalData.system;
      e && a && e!=undefined && a!=undefined && wx.setNavigationBarColor({
        frontColor: "#ffffff",
        backgroundColor: e
      }), t.setData({
        color: e,
        system: a
      });

      console.log('============',e,a,'-----------+++');
    var n = this;
    (e&&a) || n.util.request({
      url: "entry/wxapp/GetSystem",
      success: function(e) {
         console.log('================getSystemstar==========')
          n.globalData.color = e.data.color 
          n.globalData.system = e.data
          n.getSystem(t);
      }
    });

    console.log('================getSystemEnd==========')
  },
  setNavigationBarColor: function(t) {
    var e = this.globalData.color;
    if (e == undefined) {} else {
      wx.setNavigationBarColor({
        frontColor: "#ffffff",
        backgroundColor: e
      }), t.setData({
        color: e
      });

    }
    var a = this;
    e || a.util.request({
      url: "entry/wxapp/getSystem",
      success: function(e) {
        getApp().xtxx = e.data, a.globalData.color = e.data.color, a.setNavigationBarColor(t);
      }
    });
  },
  getUserInfoZ: function (callback){
    var self = this
    wx.login({
      success: function(e) {
        self.util.request({
          url: "entry/wxapp/Openid",
          cachetime: "0",
          data: {
            code: e.code
          },
          success: function (e) {
            getApp().session_key = e.data.session_key
            getApp().OpenId = e.data.openid
            getApp().getSK = e.data.session_key;
            var openid = e.data.openid;
            wx.getUserInfo({
              withCredentials:false,
              fail:function(){
                // console.warn('sssssssssssssssss getUserInfo fail')
              },
              success: function (e) {
                // console.warn('sssssssssssssssss')
                self.util.request({
                  url: "entry/wxapp/login",
                  cachetime: "0",
                  data: {
                    openid: openid,
                    img: e.userInfo.avatarUrl,
                    name: e.userInfo.nickName
                  },
                  success: function (e) {
                    console.log('zhenyi_检测到用户已经授权')
                    // console.log(e)
                    getApp().getuniacid = e.data.uniacid
                    getApp().user_info = e.data
                    // wx.setStorageSync("userInfo", e.data)
                    wx.setStorageSync("userInfo", e.data)
                    wx.setStorageSync("openid", openid)
                    callback();
                  }
                });
              }
            })
          }
        });
      }
    })
    // self.util.request({
    //   url: "entry/wxapp/login",
    //   cachetime: "0",
    //   data: {
    //     openid: t,
    //     img: "",
    //     name: ""
    //   },
    //   success: function (e) {
        
    //   }
    // });
  },
  getUserInfo: function(o) {
    var a = this;
    wx.login({
      success: function(e) {
        a.util.request({
          url: "entry/wxapp/Openid",
          cachetime: "0",
          data: {
            code: e.code
          },
          success: function(e) {
            console.log(e), getApp().session_key = e.data.session_key, getApp().OpenId = e.data.openid,
              getApp().getSK = e.data.session_key;
            var t = e.data.openid;
            wx.getSetting({
              success: function(e) {
                1 != e.authSetting["scope.userInfo"] ? (console.log("检测到用户没有授权"), a.util.request({
                  url: "entry/wxapp/login",
                  cachetime: "0",
                  data: {
                    openid: t,
                    img: "",
                    name: ""
                  },
                  success: function(e) {
                    getApp().getuniacid = e.data.uniacid, getApp().user_info = e.data, wx.setStorageSync("userInfo", e.data),
                      o(e.data);
                    var t = getCurrentPages(),
                      a = t[t.length - 1],
                      n = a.route;
                    a.options;
                    "zh_gjhdbm/pages/index/index" != n && wx.navigateTo({
                      url: "../login/index"
                    });
                  }
                })) : (console.log("检测到用户已经授权"), wx.getUserInfo({
                  withCredentials: !1,
                  success: function(e) {
                    a.util.request({
                      url: "entry/wxapp/login",
                      cachetime: "0",
                      data: {
                        openid: t,
                        img: e.userInfo.avatarUrl,
                        name: e.userInfo.nickName
                      },
                      success: function(e) {
                        console.log('zhenyi_检测到用户已经授权')
                        console.log(e), getApp().getuniacid = e.data.uniacid, getApp().user_info = e.data,
                          wx.setStorageSync("userInfo", e.data), o(e.data);
                      }
                    });
                  }
                }));
              }
            });
          }
        });
      }
    });
  },
  getUserinfo: function(e) {
    if ("" != wx.getStorageSync("userInfo").img) return !0;
    wx.showModal({
      title: "温馨提示",
      content: "您需要授权才能正常使用小程序",
      success: function(e) {
        e.confirm ? wx.navigateTo({
          url: "../login"
        }) : getApp().getUserinfo();
      }
    });
  },
  toLoginPage(){
    wx.navigateTo({
      url: "../login"
    })
  },
  fmtDate2: function (unixtimestamp){
    var unixtimestamp = new Date(unixtimestamp*1000);
        var year = 1900 + unixtimestamp.getYear();
        var month = "0" + (unixtimestamp.getMonth() + 1);
        var date = "0" + unixtimestamp.getDate();
        var hour = "0" + unixtimestamp.getHours();
        var minute = "0" + unixtimestamp.getMinutes();
        var second = "0" + unixtimestamp.getSeconds();
        return year + "-" + month.substring(month.length-2, month.length)  + "-" + date.substring(date.length-2, date.length)
            + " " + hour.substring(hour.length-2, hour.length) + ":"
            + minute.substring(minute.length-2, minute.length) + ":"
            + second.substring(second.length-2, second.length);
  },
  fmtDate: function (obj){
    var date =  new Date(obj);
    var y = 1900+date.getYear();
    var m = "0"+(date.getMonth()+1);
    var d = "0"+date.getDate();
    return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length);
  },
  ormatDate: function(e) {
    var t = new Date(1e3 * e);
    return t.getFullYear() + "-" + a(t.getMonth() + 1, 2) + "-" + a(t.getDate(), 2) + " " + a(t.getHours(), 2) + ":" + a(t.getMinutes(), 2) + ":" + a(t.getSeconds(), 2);

    function a(e, t) {
      for (var a = "" + e, n = a.length, o = "", r = t; r-- > n;) o += "0";
      return o + a;
    }
  },
  week: function(e) {
    return ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"][new Date(Date.parse("2008-08-08".replace(/-/g, "/"))).getDay()];
  },
  contains: function(e, t) {
    for (var a = e.length; a--;)
      if (e[a].src === t) return a;
    return !1;
  },
  today: function() {
    var e = new Date(),
      t = e.getFullYear(),
      a = e.getMonth() + 1,
      n = e.getDate();
    return 1 <= a && a <= 9 && (a = "0" + a), 0 <= n && n <= 9 && (n = "0" + n), t + "-" + a + "-" + n;
  },
  time: function(e) {
    return new Date(1e3 * parseInt(e)).toLocaleString().replace(/:\d{1,2}$/, " ");
  },
  today_time: function(e) {
    var t = new Date(),
      a = t.getMonth() + 1,
      n = t.getDate();
    1 <= a && a <= 9 && (a = "0" + a), 0 <= n && n <= 9 && (n = "0" + n);
    var o = t.getHours(),
      r = t.getMinutes(),
      i = t.getSeconds();
    return o <= 9 && (o = "0" + o), r <= 9 && (r = "0" + r), i <= 9 && (i = "0" + r),
      t.getFullYear() + "-" + a + "-" + n + " " + o + ":" + r + ":" + i;
  },
  yestoday: function(e) {
    var t = new Date().getTime() - 864e5,
      a = new Date();
    a.setTime(t);
    var n = a.getFullYear(),
      o = a.getDate(),
      r = a.getMonth() + 1;
    return r < 10 && (r = "0" + r), n + "-" + r + "-" + o;
  },
  convertHtmlToText: function(e) {
    var t = "" + e;
    return t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = (t = t.replace(/<\/div>/gi, "\r\n")).replace(/<\/li>/gi, "\r\n")).replace(/<li>/gi, "  *  ")).replace(/<\/ul>/gi, "\r\n")).replace(/<br\s*[\/]?>/gi, "\r\n")).replace("?", "\n")).replace(/<p.*?>/gi, "\r\n")).replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 ($1)")).replace(/<script.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/script>/gi, "")).replace(/<style.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/style>/gi, "")).replace(/<(?:.|\s)*?>/g, "")).replace(/(?:(?:\r\n|\r|\n)\s*){2,}/gim, "\r\n\r\n")).replace(/ +(?= )/g, "")).replace(/ /gi, " ")).replace(/&/gi, "&")).replace(/"/gi, '"')).replace(/</gi, "<")).replace(/>/gi, ">");
  },
  downLoadImg: function(e) {
    wx.downloadFile({
      url: e,
      success: function(e) {
        e.tempFilePath;
      }
    });
  },
  util: require("we7/resource/js/util.js"),
  tabBar: {
    color: "#123",
    selectedColor: "#1ba9ba",
    borderStyle: "#1ba9ba",
    backgroundColor: "#fff",
    list: [{
      pagePath: "/we7/pages/index/index",
      iconPath: "/we7/resource/icon/home.png",
      selectedIconPath: "/we7/resource/icon/homeselect.png",
      text: "首页"
    }, {
      pagePath: "/we7/pages/user/index/index",
      iconPath: "/we7/resource/icon/user.png",
      selectedIconPath: "/we7/resource/icon/userselect.png",
      text: "微擎我的"
    }]
  },
  globaldata: {
    name: "你在搞笑么？"
  },
  globalData: {
    userInfo: null,
    sele_city: 1
  }
});